.TH std::experimental::ranges::search 3 "2024.06.10" "http://cppreference.com" "C++ Standard Libary"
.SH NAME
std::experimental::ranges::search \- std::experimental::ranges::search

.SH Synopsis
   Defined in header <experimental/ranges/algorithm>
   template< ForwardIterator I1, Sentinel<I1> S1,

             ForwardIterator I2, Sentinel<I2> S2, class Pred =
   ranges::equal_to<>,
             class Proj1 = ranges::identity, class Proj2 =
   ranges::identity >                                                   \fB(1)\fP (ranges TS)
       requires IndirectlyComparable<I1, I2, Pred, Proj1, Proj2>
   I1 search( I1 first1, S1 last1, I2 first2, S2 last2,

              Pred pred = Pred{}, Proj1 proj1 = Proj1{}, Proj2 proj2 =
   Proj2{} );
   template< ForwardRange R1, ForwardRange R2, class Pred =
   ranges::equal_to<>,

             class Proj1 = ranges::identity, class Proj2 =
   ranges::identity >
       requires IndirectlyComparable<ranges::iterator_t<R1>,
   ranges::iterator_t<R2>,                                              \fB(2)\fP (ranges TS)
                                     Pred, Proj1, Proj2>
   ranges::safe_iterator_t<R1> search( R1&& r1, R2&& r2, Pred pred =
   Pred{},

                                       Proj1 proj1 = Proj1{}, Proj2
   proj2 = Proj2{} );

   1) Searches for the first occurrence of the sequence of elements [first2, last2) in
   the range [first1, last1). Elements are compared using pred after being projected
   with proj2 and proj1, respectively.
   2) Same as \fB(1)\fP, but uses r1 as the first source range and r2 as the second source
   range, as if using ranges::begin(r1) as first1, ranges::end(r1) as last1,
   ranges::begin(r2) as first2, and ranges::end(r2) as last2.

   Notwithstanding the declarations depicted above, the actual number and order of
   template parameters for algorithm declarations is unspecified. Thus, if explicit
   template arguments are used when calling an algorithm, the program is probably
   non-portable.

.SH Parameters

   first1, last1 - the range of elements to examine
   r1            - the range of elements to examine
   first2, last2 - the range of elements to search for
   r2            - the range of elements to search for
   pred          - predicate to apply to the projected elements
   proj1         - projection to apply to the elements in the first range
   proj2         - projection to apply to the elements in the second range

.SH Return value

   An iterator to the beginning of first occurrence of the sequence [first2, last2) in
   the range [first1, last1). If [first2, last2) is empty, first1 is returned. If no
   such occurrence is found, an iterator that compares equal to last1 is returned.

.SH Complexity

   At most S * N applications of the predicate and each projection, where S = last2 -
   first2 and N = last1 - first1.

.SH Possible implementation

   template<ForwardIterator I1, Sentinel<I1> S1,
            ForwardIterator I2, Sentinel<I2> S2, class Pred = ranges::equal_to<>,
            class Proj1 = ranges::identity, class Proj2 = ranges::identity>
       requires IndirectlyComparable<I1, I2, Pred, Proj1, Proj2>
   I1 search(I1 first1, S1 last1, I2 first2, S2 last2,
             Pred pred = Pred{}, Proj1 proj1 = Proj1{}, Proj2 proj2 = Proj2{})
   {
       for (; ; ++first1)
       {
           I1 it = first1;
           for (I2 it2 = first2; ; (void)++it, (void)++it2)
           {
               if (it2 == last2)
                   return first1;
               if (it == last1)
                   return it;
               if (!ranges::invoke(pred, ranges::invoke(proj1, *it),
                                         ranges::invoke(proj2, *it2)))
                   break;
           }
       }
   }

.SH Example

    This section is incomplete
    Reason: no example

.SH See also

   search                  searches for a range of elements
                           \fI(function template)\fP
   find_end                finds the last sequence of elements in a certain range
                           \fI(function template)\fP
   includes                returns true if one set is a subset of another
                           \fI(function template)\fP
   equal                   determines if two sets of elements are the same
                           \fI(function template)\fP
   find                    finds the first element satisfying specific criteria
   find_if                 \fI(function template)\fP
   find_if_not
                           returns true if one range is lexicographically less than
   lexicographical_compare another
                           \fI(function template)\fP
   mismatch                finds the first position where two ranges differ
                           \fI(function template)\fP
                           searches for a number consecutive copies of an element in a
   search_n                range
                           \fI(function template)\fP

.SH Category:
     * Todo no example
